<template>
  <div>
    <div class="slot">
      <div class="top">
        <div class="return" @click="goback">
          <img src="@/assets/my/zuo.png" alt />
        </div>
      </div>
    </div>
    <div class="main">
      <div class="title">
        <div class="p1">绑定您的手机号</div>
        <div class="p2">可以使我们能尽快联系到您</div>
      </div>
    </div>
    <form class="form">
      <div class="list">
        <div class="list_top">
          <img src="@/assets/home/lianxi.png" alt />
          <span>联系方式</span>
        </div>
        <div class="list_main">
          <input
            class="input"
            maxlength="11"
            placeholder="请输入联系电话"
            type="number"
            v-model="phone"
          />
        </div>
      </div>
      <div class="list">
        <div class="list_top">
          <img src="@/assets/home/yzhm.png" alt />
          <span>验证码</span>
        </div>
        <div class="list_main">
          <div>
            <input
              class="input"
              placeholder="请输入短信验证码"
              type="number"
              v-model="yzhm"
            />
          </div>
          <div>
            <span v-show="show" @click="huoquyzhm()">获取验证码</span>
            <span v-show="!show">{{ count }}s</span>
          </div>
        </div>
      </div>
      <div class="login">
        <div class="top">
          <img
            v-if="!isagree"
            src="@/assets/home/noxuan.png"
            @click="clickisagree"
            alt
          />
          <img v-else src="@/assets/home/xuan.png" @click="clickisagree" alt />
          <div class="p1">
            阅读并同意
            <span style="color: #222222">
              《
              <span style="color: #fdd40a">栋栋分润</span>用户协议》
            </span>
          </div>
        </div>
        <div class="btn" @click="submit">登录</div>
      </div>
    </form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      isagree: false,
      phone: null,
      yzhm: "",
      count: "",
      show: true,
      token: "",
      code: "",
    };
  },
  created() {
   
  },
  mounted() {
    this.token = window.localStorage.getItem("token");
  },
  methods: {
    goback() {
      this.$router.back();
    },
    clickisagree() {
      this.isagree = !this.isagree;
    },
    huoquyzhm() {
      console.log(this.phone);
      if (this.phone == null) {
        this.$toast("电话号码不能为空~");
      } else {
        axios
          .post("/index/send/index", this.$qs.stringify({
            phone: this.phone,
          }))
          .then((res) => {
            console.log(res, 789456);
            if (res.data.code == 1) {
              this.$toast(res.data.msg);
            } else {
              this.$toast(res.data.msg);
            }
          });
        const TIME_COUNT = 60;
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.show = false;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000);
        }
      }
    },
    submit() {
      if (this.phone == null) {
        return this.$toast("手机号码不能为空");
      }
      if (this.yzhm == "") {
        return this.$toast("验证码不能为空");
      }
      if (this.isagree == false) {
        return this.$toast("请勾选用户协议");
      }
      axios
        .post("/index/user/bphone", this.$qs.stringify({
          token: this.token,
          code: this.yzhm,
          phone: this.phone,
        }))
        .then((res) => {
          if (res.data.code == 1) {
            this.$toast(res.data.msg);
            window.localStorage.setItem("state", 1);
            window.localStorage.setItem("settle_in", res.data.data.settle_in);
            this.$router.push({
              path: "/home",
            });
          } else {
            this.$toast(res.data.msg);
            window.localStorage.setItem("token", "");
            axios.post("index/index/wxLogin").then((res) => {
              var http = res.data.data;
              window.location.href = http;
            });
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.slot {
  width: 100%;
  height: 44px;
  .top {
    width: 100%;
    height: 44px;
    display: flex;
    display: -webkit-flex;
    justify-content: center;
    align-items: center;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
    .return {
      width: 38px;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      display: -webkit-flex;
      justify-content: center;
      align-items: center;
      img {
        width: 8px;
        height: 15px;
      }
    }
    span {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
      line-height: 44px;
    }
  }
}
.main {
  width: 325px;
  margin: auto;
  .title {
    .p1 {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
      line-height: 18px;
      margin-top: 15px;
    }
    .p2 {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #888888;
      line-height: 14px;
      margin-top: 10px;
    }
  }
}
.form {
  width: 100%;
  margin-top: 55px;
  .list {
    width: 325px;
    height: 80px;
    margin: auto;
    border-bottom: 1px solid #efefef;
    .list_top {
      display: flex;
      display: -webkit-flex;
      align-items: center;
      margin-top: 17px;
      img {
        width: 17px;
        height: 17px;
        margin-right: 10px;
      }
      span {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #222222;
        line-height: 14px;
      }
    }
    .list_main {
      display: flex;
      display: -webkit-flex;
      align-items: center;
      position: relative;
      .input {
        border: none;
        font-size: 17px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 45px;
        padding-left: 27.5px;
      }
      span {
        display: block;
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #ff511e;
        position: absolute;
        right: 0;
      }
    }
  }
  .login {
    width: 100%;
    height: 100px;
    border-top: 1px solid #efefef;
    margin-top: 145px;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    align-items: center;
    .top {
      display: flex;
      display: -webkit-flex;
      justify-content: center;
      align-items: center;
      margin-top: 11px;
      img {
        width: 16px;
        height: 16px;
        margin-right: 6px;
      }
      .p1 {
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #999999;
        line-height: 12px;
      }
    }
    .btn {
      width: 225px;
      height: 42px;
      background: #fdd40a;
      border-radius: 21px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #222222;
      line-height: 42px;
      text-align: center;
      border: none;
      margin-top: 40px;
    }
  }
}
</style>